#include "Node.h"


using namespace gull::core;
using namespace std;


ostream&
operator<<(ostream& o,const Node& n)
{   
    o << "- NodeName: "<< n.getName() << endl << "  Children: " ;
    const std::vector<Node*>* children = n.getChildren();
    for (int i = 0; i < children->size(); ++i) {
            o << (*children)[i]->getName() << " ";
    }
    return (o << endl);
}


Node::Node(const char* name):
m_children(NULL),
m_parent(NULL),
m_name(NULL)
{
    m_name = new char[strlen(name)];
    strcpy(m_name,name);
}


Node::Node(const Node& node):
m_children(node.m_children),
m_parent(node.m_parent)
{
    m_name = new char[strlen(node.m_name)];
    strcpy(m_name, node.m_name);
}

Node::~Node()
{
#if DEBUG
	cout << "Destruction node: "<< m_name << endl;
#endif
	
    delete m_name;
    for (int i = 0; i < m_children.size(); ++i) {
        delete m_children[i];
    }
    m_children.clear();
    m_name = NULL;
    m_parent = NULL;
}

Node&
Node::operator=(const Node& node)
{
    if(&node != this)
    {
        delete m_name;
        m_children = node.m_children;
        m_name = new char[strlen(node.m_name)];
        strcpy(m_name, node.m_name);
        m_parent = node.m_parent;
    }
    return *this;
}


void 
Node::addChild(Node* child)
{
    if (child && (this != child)) 
    {
        m_children.push_back(child);
        child->setParent(this);
    }
    
}

void 
Node::removeChild(Node* child)
{

}

void 
Node::removeAllChildren()
{
    
}



